#include <bits/stdc++.h>

using namespace std;

#define uLL unsigned long long

int main()
{
    uLL num;
    cin >> num;
    int n;
    cin >> n;
    const uLL multiplier = 47055833459ULL;
    if (num > ULLONG_MAX / multiplier)
    {
        // 2^32 * 2^32 -> 2^64
        uLL high1 = num >> 32;
        uLL low1 = num & 0xFFFFFFFFULL;

        uLL high2 = multiplier >> 32;
        uLL low2 = multiplier & 0xFFFFFFFFULL;

        uLL a = low1 * low2;
        uLL b = low1 * high2;
        uLL c = high1 * low2;
        uLL d = high1 * high2;

        uLL mid = (a >> 32) + (b & 0xFFFFFFFFULL) + (c & 0xFFFFFFFFULL);
        uLL high = d + (b >> 32) + (c >> 32) + (mid >> 32);
        uLL low = (mid << 32) + (a & 0xFFFFFFFFULL);

        int shift = 64 - n;
        uLL result = (high << n) | (low >> shift);

        return result % (1ULL << n);
    }
    // system("pause");
    return 0;
}
